#include <windows.h>
#include <cstdio>
#include "DxManager.h"

#ifndef COMMON_H
#define COMMON_H

class T_Block
{
private:
	char c;
	bool Occ;
	int color;
	RECT srcRect;
	RECT destRect;
	
public:
	IDirect3DSurface9 * T_BlockSurface;
	IDirect3DSurface9 * red;
	IDirect3DSurface9 * blue;
	IDirect3DSurface9 * green;
	IDirect3DSurface9 * yellow;
	IDirect3DSurface9 * purple;
	IDirect3DSurface9 * orange;
	IDirect3DSurface9 * white;

	T_Block() {Occ = false;}
	void Init(DxManager * dxm) 
	{ 
		Occ = false;
		red = dxm->loadSurfaceFromBitmap("T_BLOCK_RED.bmp", 30, 30);
		blue = dxm->loadSurfaceFromBitmap("T_BLOCK_BLUE.bmp", 30, 30);
		green = dxm->loadSurfaceFromBitmap("T_BLOCK_GREEN.bmp", 30, 30);
		yellow = dxm->loadSurfaceFromBitmap("T_BLOCK_YELLOW.bmp", 30, 30);
		purple = dxm->loadSurfaceFromBitmap("T_BLOCK_PURPLE.bmp", 30, 30);
		orange = dxm->loadSurfaceFromBitmap("T_BLOCK_ORANGE.bmp", 30, 30);
		white = dxm->loadSurfaceFromBitmap("T_BLOCK_WHITE.bmp", 30, 30);
		
		srcRect.left = 0;
		srcRect.top = 0;
		srcRect.bottom = srcRect.top + 30;
		srcRect.right = srcRect.left + 30;
	}
	void BlockColor(int Col) { color = Col; }
	int getColor() { return color; }
	RECT getRect() { return destRect; }
	void SetTrue() { Occ = true; }
	void SetFalse() { Occ = false; }
	bool GetOccupation() { return Occ; }
	void Draw(DxManager * dxm, int x, int y, int color)
	{
		destRect.left = x * 15;
		destRect.top = y * 15;
		destRect.bottom = destRect.top + 15;
		destRect.right = destRect.left + 15;
		switch(color)
		{
		case RED:
			T_BlockSurface = red;
			break;
		case BLUE:
			T_BlockSurface = blue;
			break;
		case GREEN:
			T_BlockSurface = green;
			break;
		case YELLOW:
			T_BlockSurface = yellow;
			break;
		case PURPLE:
			T_BlockSurface = purple;
			break;
		case ORANGE:
			T_BlockSurface = orange;
			break;
		case WHITE:
			T_BlockSurface = white;
			break;
		}
		dxm->blitToSurface(T_BlockSurface, &srcRect, &destRect);

	}

};

#endif